package com.example.lista_zadan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class SpecialAdapter extends BaseAdapter {
    private int[] colors = new int[] { 0xAAf6ffc8 , 0xAA538d00 };
    private LayoutInflater mInflater;
    private ArrayList<String> data;

    public SpecialAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
        this.data = new ArrayList<String>();
    }

    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    public String getItemString(int position) {
        return data.get(position).toString();
    }

    public void removeItem(int position) {
        data.remove(position);
    }

    public void addItem(String item) {
        this.data.add(item);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.headline);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(data.get(position));
        int colorPos = position % colors.length;
        convertView.setBackgroundColor(colors[colorPos]);
        return convertView;
    }

}
